<?php
/*
 Plugin Name: Recent New
 Plugin URI: http://website-in-a-weekend.net/plugins/
 Description: Plugin for fngroup.vn site
 Version: 0.1
 Author: Binh Dang
 Author URI: http://website-in-a-weekend.net/plugins/
 */
 
/*  Copyright 2009  Dave Doolin  (email : david.doolin@gmail.com)
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 (at your option) any later version.
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */
 
/**
 * This plugin exists only to demonstrate _exactly_ how a database 
 * table is set up and torn down.
 */


	add_action("admin_init", "recent_init");   
	function recent_init(){
		add_meta_box("product-meta", "Check recent new", "add_meta_box_recent_post", "post", "normal", "low"); 	 
	}  
	 
	 function add_meta_box_recent_post( $object, $box){ 
		//
		global $post; $custom = get_post_custom($post->ID); $product_completed = $custom["product-meta"][0];
		wp_nonce_field( basename( __FILE__ ), 'smashing_post_class_nonce' );
		 ?>
			<p>
				
				<input  style="margin-left: 0 !important; width: 20px;" type="checkbox" name="recent_post" <?php if(get_post_meta( $object->ID, 'recent_post', true ) =="on") echo "checked" ?>  />	
				<label for="tour_featured">			
				Recent New</label>			
				
			</p>	
			

		<?php		
	}
	add_action( 'save_post', 'post_recent_post', 10, 2 );	
	/* Save the meta box's post metadata. */
	function post_recent_post( $post_id, $post ) {
		/* Verify the nonce before proceeding. */
		if ( !isset( $_POST['smashing_post_class_nonce'] ) || !wp_verify_nonce( $_POST['smashing_post_class_nonce'], basename( __FILE__ ) ) )
			return $post_id;

		/* Get the post type object. */
		$post_type = get_post_type_object( $post->post_type );

		/* Check if the current user has permission to edit the post. */
		if ( !current_user_can( $post_type->cap->edit_post, $post_id ) )
			return $post_id;
		/* Get the posted data and sanitize it for use as an HTML class. */
		$recent_post = ( isset( $_POST['recent_post'] ) ?  $_POST['recent_post'] : '' );
		/* Get the meta key. */
		$key_recent_post = 'recent_post';
		/* Get the meta value of the custom field key. */
		$old_recent_post = get_post_meta( $post_id, $key_recent_post, true );
		/* === Product name === */
		if ( $recent_post && '' == $old_recent_post )
			add_post_meta( $post_id, $key_recent_post, $recent_post, true );	
		elseif ( $recent_post && $recent_post != $old_recent_post )
			update_post_meta( $post_id, $key_recent_post, $recent_post );	
		elseif ( '' == $recent_post && $old_recent_post )
			delete_post_meta( $post_id, $key_recent_post, $recent_post );	
	}
	
